package com.my.kq.controller;

import com.my.kq.entity.Employee;
import com.my.kq.service.EmployeeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/EmployeeDlu")
//登陆
public class EmployeeDlu extends HttpServlet {
    private EmployeeService EmployeeService=new EmployeeService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("utf-8");
            resp.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;charset=utf-8");
            String employeeNumber = req.getParameter("employeeNumber");
            String password = req.getParameter("password");
            Employee dlu = EmployeeService.dlu(employeeNumber, password);
            HttpSession session = req.getSession();
            if(dlu.getId()>0){
                session.setAttribute("cook",dlu);
                req.getRequestDispatcher("jsp/admin/home.jsp").forward(req,resp);
            }else {
                req.getRequestDispatcher("login.jsp").forward(req,resp);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
